<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="CommonUtil/CommonUtil.js"></script>
    <script type="text/javascript" charset="utf-8">
        window.onload = function () {
            //给一个元素设置样式
            //var element = document.getElementById('div1');
            //element.style.color = 'red';
            //给多个元素设置一样的样式
            //setStyle(['div1','div2','div3'],'color','red');
            setCss(['div1','div2','div3'],{
                //position:'absolute',
                background:'green',
                fontSize:'18px',
                left:'100px'
                }
            )
        }
        function setStyle(elementsId,prop,val) {
           for(var i = 0;i<elementsId.length;i++){
               document.getElementById(elementsId[i]).style[prop] = val;
           }
        }
        function setCss(elemnetsId,options) {
            for(var prop in options){
                if(!options.hasOwnProperty(prop)){
                    continue;
                }
                setStyle(elemnetsId,prop,options[prop]);
            }
        }
    </script>
</head>
<body>
    <div id="div1">我是div1</div>
    <div id="div2">我是div2</div>
    <div id="div3">我是div3</div>
</body>
</html>